package project.parser.ast.exps.op.binary;

import project.environments.DynamicEnv;
import project.environments.StaticEnv;
import project.environments.Value;
import project.parser.ast.exps.Exp;
import project.parser.ast.types.PrimType;
import project.parser.ast.types.Type;
import project.parser.ast.util.TypecheckUtil;
import project.parser.ast.values.BoolValue;
import project.parser.tokenizer.TokenType;

public class And extends BinaryOp {
	public And(Exp left, Exp right) {
		super(left, right);
	}

	@Override
	protected String opToString() {
		return TokenType.AND.toString();
	}

	@Override
	public Type typecheck(StaticEnv senv) {
		return TypecheckUtil.checkType(senv, PrimType.BOOLEAN_TYPE, left, right);
	}

	@Override
	public Value evaluate(DynamicEnv denv) {
		return new BoolValue(left.evaluate(denv).asBoolean() && right.evaluate(denv).asBoolean());
	}

}
